package com.lzhsite.technology.designPattern.factory.TextImageReadDemo;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
 *  类描述：图像文件读取
 *           
 */
public class ImageRead implements IRead<ImageInfo>{
 
	public ImageInfo read(String... in) {
		BufferedImage bi = null;
		File f = new File(in[0]);//in[0]存储文件名
		
		try {
			bi = ImageIO.read(f);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		int width = bi.getWidth();
		int height = bi.getHeight();
		int rgb[] = new int[width * height];
		
		bi.getRGB(0, 0, width, height, rgb, width, height);
		ImageInfo info = new ImageInfo();
		info.setWidth(width);
		info.setHeight(height);
		info.setRGB(rgb);
		
		
		return info;
	}
}
 